// pages/home/home.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name:'芜湖职业技术学院大数据专业2022',
    grade:2010,
    canIUseGetUserProfile: false,
    isShowUserName: false,
    userInfo: null,
  },
  userLogin:function(e){
    console.log("userLogin")
    wx.login({
      timeout: 1110,
      success:res=>{
        console.log(res)
      }
    })
  },
  click1:function(e){
    console.log('按钮1被点击了....')
    //this.data.name = "安徽芜湖" 不好用

    //页面数据的修改
    this.setData({
        name:'安徽芜湖'
    })

  },
  getUserProfile:function(e){
        wx.getUserProfile({
          desc: '获取会员信息',
          success:res=>{
              console.log(res)
              let weixin = {}
              weixin['avatarUrl'] = res.userInfo.avatarUrl
              weixin['nickName'] = res.userInfo.nickName
              weixin['country'] = res.userInfo.country
              weixin['city'] = res.userInfo.city
              weixin['gender'] = res.userInfo.gender
              this.setData({
                userInfo:weixin,
                isShowUserName: true
            })
            //本地存储获取到的学生数据信息
            wx.setStorageSync('userInfo', weixin)
          },
          fail:res=>{
              console.log(res)
          }
        })
  },

  onLoad(options) {
     //当前能否用新的接口，能用则用，canIUseGetUserProfile置为true
        if (wx.getUserProfile) {
            this.setData({
                canIUseGetUserProfile: true
            })
        }

        //已经登录过，直接显示用户的信息
        if(wx.getStorageSync('userInfo')){
            this.setData({
                userInfo:wx.getStorageSync('userInfo')
                
            })
            
        }
  },
 
 
 

   
})